package com.itheima.controller;

import com.itheima.entity.Employee;
import com.itheima.jsonresult.JsonResult;
import com.itheima.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/employee")
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    /**
     * 新增员工
     * @param employee
     * @return
     */
    @PostMapping
    public JsonResult add(@RequestBody Employee employee){
        return employeeService.add(employee);
    }

    /**
     *启用/禁用/修改
     * @param employee
     * @return
     */
    @PutMapping
    public JsonResult put(@RequestBody Employee employee){
        return employeeService.put(employee);
    }

    /**
     * 员工登录
     * @param employee
     * @return
     */
    @PostMapping("/login")
    public JsonResult login(@RequestBody Employee employee){
        return employeeService.login(employee);
    }

    /**
     * 员工登出
     * @param request
     * @return
     */
    @PostMapping("/logout")
    public JsonResult logout(HttpServletRequest request){
        return employeeService.logout(request);
    }

    /**
     * 员工分页查询
     * @param name
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/page")
    public JsonResult getPage(String name, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pageSize){
        return employeeService.getPage(name,page,pageSize);
    }

    /**
     * 根据id查询员工接口
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public JsonResult getEmployeeById(@PathVariable String id) {
        return employeeService.getEmployeeById(id);
    }



}
